﻿using System;

namespace _15_使用按引用传递的返回值
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("------------不使用按引用传递的返回值-----------------------");
            Test1 t1 = new Test1(100);
            Console.WriteLine("初始值：");
            t1.DisplayValue();
            int x = t1.Value;
            x = 200;
            Console.WriteLine("修改属性返回值 之后：");
            t1.DisplayValue();

            Console.WriteLine("\n----------使用按引用传递的返回值---------------------");
            Test2 t2 = new Test2(100);
            Console.WriteLine("初始值：");
            t2.DisplayVale();
            ref int y = ref t2.value;
            y = 200;
            Console.WriteLine("修改属性返回值之后：");
            t2.DisplayVale();

        }
    }

    class Test1
    {
        private int _local;

        public Test1(int init)
        {
            _local = init;
        }

        public void DisplayValue()
        {
            Console.WriteLine($"当前值 ：{_local}");
        }

        public int Value => _local;
    }

    class Test2
    {

        private int _local;

        public Test2(int init)
        {
            _local = init;
        }

        public void DisplayVale()
        {
            Console.WriteLine($"当前值：{_local}");
        }

        public ref int value => ref _local;
    }
}
